<?php
namespace app\admin\controller\finance;
use app\admin\controller\Controller;
use app\admin\model\finance\LargeOrder as LargeOderModel;
use app\admin\model\finance\LargeWithdraw as LargeWithdrawModel;
use think\Db;
use think\Session;

/**
 *  商户大额充值
 * Class Large
 * @package app\admin\controller\finance
 */
class Large extends Controller
{

    public function index(){
        // 订单列表
        $model = new LargeOderModel;
        $list = $model->getList($this->request->param());
        return $this->fetch('index', compact('list'));
    }

    public function withdraw(){
        $model = new LargeWithdrawModel;
        $list = $model->getList($this->request->param());
        return $this->fetch('withdraw', compact('list'));
    }



    public function adopt($id){
        $model = new LargeWithdrawModel;
        $res= $model->where('id',$id)->setField('apply_status',20);
        if ($res) {
            return $this->renderSuccess('操作成功');
        }
        return $this->renderError('操作失败');
    }

    public function thaw($id){
        $model = new LargeWithdrawModel;
        $admin=Session::get('yoshop_adminuser');
        $res= $model->where('id',$id)->setField(['apply_status'=>20,'admin_id'=>$admin['user']['admin_user_id'],'update_time'=>time()]);
        if ($res==1) {
            return $this->renderSuccess('操作成功');
        }
        return $this->renderError('操作失败');
    }

    public function refuse(){
        $params=input();
        $model = new LargeWithdrawModel;
        $admin=Session::get('yoshop_adminuser');
        $withdraw=$model->find($params['id']);
        Db::transaction(function () use ($model,$withdraw,$admin,$params) {
            $res=$model->where('id',$params['id'])->setField(['apply_status'=>30,'admin_id'=>$admin['user']['admin_user_id'],'update_time'=>time(),'back_reason'=>$params['message_content']]);
            if($res){
                $ext= json_encode([
                    'withdraw_id'=>$params['id'],
                ]);
                \app\common\model\store\StoreNotice::add($withdraw['wxapp_id'],2, $params['id'],$params['message_title'],$params['message_content'],$ext);
            }
        });

        return $this->renderSuccess('操作成功');
    }


}